Rank 'em
Create a survey asking people to rank things, and this script will validate that everything is ranked, and no rankings are repeated.
Forms
You can incorporate this validation feature into any existing form, any number of times.
The form elements must be named consistently so the script can work with them.
To set up a ranked-list survey question as in the examples above, name the s
as q + the number of the question + a, b, c, etc. In this case, the form elements are named:
q1a
q1b
q1c
q1d
q2a
q2b
q2c
q2d
q2e
To use the validation, call rankem(a,b) where the parameters are the question number and its length.
In this case, the form handler calls the function twice:
rankem(1,4);
rankem(2,5);
Each call will generate a separate alert if there's anything amiss. The global "badrank" variable
is a status flag so the main form handler knows if it's allowed to submit(). Note that this demo
doesn't acutally do a submit(); instead it just displays a message.
You can incorporate this validation feature into any existing form, any number of times.
The form elements must be named consistently so the script can work with them.
To set up a ranked-list survey question as in the examples above, name the s
as q + the number of the question + a, b, c, etc. In this case, the form elements are named:
q1a
q1b
q1c
q1d
q2a
q2b
q2c
q2d
q2e
To use the validation, call rankem(a,b) where the parameters are the question number and its length.
In this case, the form handler calls the function twice:
rankem(1,4);
rankem(2,5);
Each call will generate a separate alert if there's anything amiss. The global "badrank" variable
is a status flag so the main form handler knows if it's allowed to submit(). Note that this demo
doesn't acutally do a submit(); instead it just displays a message.
NONE